package com.xiaoxu.spzx.product.controller;

import com.github.pagehelper.PageInfo;
import com.xiaoxu.spzx.model.dto.h5.ProductSkuDto;
import com.xiaoxu.spzx.model.entity.product.ProductSku;
import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import com.xiaoxu.spzx.model.vo.h5.ProductItemVo;
import com.xiaoxu.spzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value="/api/product")

public class ProductController {

	@Autowired
	private ProductService productService;

	@Operation(summary = "分页查询")
	@GetMapping(value = "/{page}/{limit}")
	public Result<PageInfo<ProductSku>> findByPage(@Parameter(name = "page", description = "当前页码", required = true) @PathVariable Integer page,
												   @Parameter(name = "limit", description = "每页记录数", required = true) @PathVariable Integer limit,
												   @Parameter(name = "productSkuDto", description = "搜索条件对象", required = false) ProductSkuDto productSkuDto) {
		PageInfo<ProductSku> pageInfo = productService.findByPage(page, limit, productSkuDto);
		return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
	}



	@Operation(summary = "商品详情")
	@GetMapping("item/{skuId}")
	public Result<ProductItemVo> item(@Parameter(name = "skuId",
											description = "商品skuId", required = true)
										  @PathVariable Long skuId) {
		ProductItemVo productItemVo = productService.item(skuId);
		return Result.build(productItemVo , ResultCodeEnum.SUCCESS);
	}

	//远程调用: 查询商品sku列表
	@Operation(summary = "根据skuId查询sku信息")
	@GetMapping("getBySkuId/{skuId}")
	public ProductSku getSkuById(@PathVariable Long skuId){

		ProductSku productSku = productService.findSkuById(skuId);

		return productSku;
	}
	}

